
export function formatTimeAll(time) {
    const datetime= new Date(time);
    const year = datetime.getFullYear();
    const month = String(datetime.getMonth() + 1).padStart(2,'0');
    const day = String(datetime.getDate()).padStart(2, '0');
    const hours = String(datetime.getHours()).padStart(2, '0');
    const minutes = String(datetime.getMinutes()).padStart(2, '0');
    return `${year}-${month}-${day} ${hours}:${minutes}`;
}

export function formatTimeAllBr(time) {
    if(time !== null || time !=undefined){
        const datetime= new Date(time);
        const year = datetime.getFullYear();
        const month = String(datetime.getMonth() + 1).padStart(2,'0');
        const day = String(datetime.getDate()).padStart(2, '0');
        const hours = String(datetime.getHours()).padStart(2, '0');
        const minutes = String(datetime.getMinutes()).padStart(2, '0');
        return `${year}-${month}-${day} \n ${hours}:${minutes}`;
    }else{
        return null
    }
    
}
export function formatTimeday(time) {
    if(time !== null || time !=undefined){
        const datetime= new Date(time);
        const year = datetime.getFullYear();
        const month = String(datetime.getMonth() + 1).padStart(2,'0');
        const day = String(datetime.getDate()).padStart(2, '0');
        return `${year}-${month}-${day}`;
    }else{
        return null
    }
    
}
export function formatTimeMouth(time) {
    if(time !== null || time !=undefined){
        const datetime= new Date(time);
        const month = String(datetime.getMonth() + 1).padStart(2,'0');
        const day = String(datetime.getDate()).padStart(2, '0');
        return `${month}-${day}`;
    }else{
        return null
    }
}

export function formatTimeMinutes(time) {
    const datetime= new Date(time);
    const hours = String(datetime.getHours()).padStart(2, '0');
    const minutes = String(datetime.getMinutes()).padStart(2, '0');
    return `${hours}:${minutes}`;
}

export function formatTimedayPlan(time) {
    if(time !== null || time !=undefined){
        const datetime= new Date(time);
        const year = datetime.getFullYear();
        const month = String(datetime.getMonth() + 1).padStart(2,'0');
        const day = String(datetime.getDate()).padStart(2, '0');
        return `${year}${month}${day}`;
    }else{
        return null
    }
}

export function connectTime(data, newpart){
    if(data !== null || data !=undefined){
    // 原始日期时间字符串
    let originalTime = data; // '2022-06-13 13:00:00'
    // 提取日期部分
    let datePart = originalTime.split(' ')[0];
    
    // 拼接上固定的时间部分
    let  newTime = `${datePart} ${newpart}`;
    return newTime
    }else{
        return null
    }
  }
// 根据传入时间返回对应的早八晚八时间
export function getTheStartTime(data){
    if(data !== null || data !=undefined){
        const endTime = new Date(data);
        let startTime;
        if (endTime.getHours() < 8 || (endTime.getHours() === 8 && endTime.getMinutes() === 0)) {
            startTime = new Date(endTime);
            startTime.setDate(endTime.getDate() - 1);
            startTime.setHours(8, 0, 0, 0);
        } else if (endTime.getHours() < 14 || (endTime.getHours() === 14 && endTime.getMinutes() === 0)) {
            startTime = new Date(endTime);
            startTime.setHours(8, 0, 0, 0);
        } else {
            startTime = new Date(endTime);
            startTime.setHours(14, 0, 0, 0);
        }
        return startTime
    }else{
        return null
    }
  }
//   提早一小时
export function getStartTimeHour(data){
    if(data !== null || data !=undefined){
        const endTime = new Date(data);
        let startTime;
        // if (endTime.getHours() == 0) {
        //     startTime = new Date(endTime);
        //     // startTime.setDate(endTime.getDate()-1);
        //     startTime.setHours(endTime.getHours() - 1, 0, 0, 0);
        // } else {
            startTime = new Date(endTime);
            startTime.setHours(endTime.getHours() - 1);
        // }
        return startTime
    }else{
        return null
    }
  }

//   240222新改
// 根据传入时间返回对应的早八晚八时间
export function getTheStartTimeNew(data){
    if(data !== null || data !=undefined){
        const endTime = new Date(data);
        let startTime;
        if (endTime.getHours() < 8 || (endTime.getHours() === 8 && endTime.getMinutes() === 0)) {
            startTime = new Date(endTime);
            startTime.setDate(endTime.getDate() - 1);
            startTime.setHours(8, 0, 0, 0);
        } else{
            startTime = new Date(endTime);
            startTime.setHours(8, 0, 0, 0);
        } 
        return startTime
    }else{
        return null
    }
  }

  export function formatTimeAllMDBrHm(time) {
    if(time !== null || time !=undefined){
        const datetime= new Date(time);
        const month = String(datetime.getMonth() + 1).padStart(2,'0');
        const day = String(datetime.getDate()).padStart(2, '0');
        const hours = String(datetime.getHours()).padStart(2, '0');
        const minutes = String(datetime.getMinutes()).padStart(2, '0');
        return `${month}-${day} <br> ${hours}:${minutes}`;
    }else{
        return "--"
    }
    
}